// MANDELBROTS FROM SPACE!!
// Something I did when getting the initial build to work-- cjb

void send_rtty_packet (void)
{
  static int yy = -1;

  if (yy == -1)
    {
      // Write a RTTY packet into the tx buffer, and start transmission.
      // Convert raw lat/lon values into degrees and decimal degree values.
      uint8_t lat_d = (uint8_t) abs(gpsData.lat_raw / 10000000);
      uint32_t lat_fl = (uint32_t) abs(abs(gpsData.lat_raw) - lat_d * 10000000) / 1000;
      uint8_t lon_d = (uint8_t) abs(gpsData.lon_raw / 10000000);
      uint32_t lon_fl = (uint32_t) abs(abs(gpsData.lon_raw) - lon_d * 10000000) / 1000;
      uint8_t speed_kph = (uint8_t)((float)gpsData.speed_raw*0.0036);

      // Produce a RTTY Sentence (Compatible with the existing HORUS RTTY payloads)
      sprintf(buf_rtty, "\n\n\n\n$$$$$%s,%d,%02u:%02u:%02u,%s%d.%04ld,%s%d.%04ld,%ld,%d,%d,%d,%d",
	      callsign,
	      send_count,
	      gpsData.hours, gpsData.minutes, gpsData.seconds,
	      gpsData.lat_raw < 0 ? "-" : "", lat_d, lat_fl,
	      gpsData.lon_raw < 0 ? "-" : "", lon_d, lon_fl,
	      (gpsData.alt_raw / 1000),
	      speed_kph,
	      gpsData.sats_raw,
	      voltage*10,
	      si4032_temperature
	      );

      // Calculate and append CRC16 checksum to end of sentence.
      CRC_rtty = string_CRC16_checksum(buf_rtty + 9);
      sprintf(buf_rtty, "%s*%04X\n", buf_rtty, CRC_rtty & 0xffff);

      // Point the TX buffer at the temporary RTTY packet buffer.
      tx_buffer = buf_rtty;

      // Enable the radio, and set the tx_on flag to 1.
      start_bits = RTTY_PRE_START_BITS;
      radio_enable_tx();
      tx_on = 1;
      // From here the timer interrupt handles things.
      yy++;
      return;
    }

  if (yy > 14)
    {
      yy = -1;
      return;
    }

  float y = -1.75 + (yy * (3.50/14.0));

  char *p = buf_rtty;
  *p++ = '\n';
  *p++ = '\n';

  for (int xx = 0; xx < 40; xx++)
    {
      float x = -2.5+ (xx*(3.0 / 40.0));
      char c = mandel (x, y);
      *p++ = 32+c;
    }
  *p++ = '\n';
  *p = 0;
  tx_buffer = buf_rtty;

  start_bits = RTTY_PRE_START_BITS;
  radio_enable_tx();
  tx_on = 1;
  yy++;
  return;
}
